<!-- 右侧播放 -->

<template>
  <WebForm class="BroadcastTask-RightPlay" :class="one.taskStatus === '1' ? 'BroadcastTask-RightPlay-disabled' : null">
    <MajorTitle title="播放控制" />

    <el-empty v-if="!one.id" description="暂无播放" />
    <div v-else class="flexCC">
      <div class="flex0" :class="one.taskStatus === '1' ? 'BroadcastTask-RightPlay-playing' : null">
        <img :src="imgs.cover" />
      </div>

      <div class="flex1">
        <b>{{ one.taskShowName || '-' }}</b>

        <div class="flex flexMiddle">
          <!-- <img v-if="one.playModeId === '2'" :src="imgs.loop" @click="changeMode('3')" />
          <img v-else-if="one.playModeId === '3'" :src="imgs.random" @click="changeMode('1')" />
          <img v-else :src="imgs.normal" @click="changeMode('2')" /> -->

          <img :src="imgs.prev" @click="changeControl('PREV')" />

          <img :src="imgs.play" @click="changeControl('PLAY')" />
          <img :src="imgs.pause" @click="changeControl('PAUSE')" />

          <img :src="imgs.next" @click="changeControl('NEXT')" />

          <span><img :src="imgs.volume" /></span>

          <FormSlider bind="taskVolume" noLabel noMargin @change="changeVolume" />

          <div>{{ one.taskVolume }}</div>
        </div>
      </div>
    </div>
  </WebForm>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'

const getImg = (name) => CORE.common(`secure/broadcast/${name}.png`)
const IMG = ['cover', 'normal', 'one', 'loop', 'random', 'prev', 'next', 'play', 'pause', 'volume', 'choose', 'del']

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'RightPlay',

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [CORE.mixWeb()],

  /**
   * 计算属性 (慎用箭头函数)
   */
  computed: {
    /**
     * 图片对象
     */
    imgs: () => IMG.reduce((obj, img) => ({ ...obj, [img]: getImg(img) }), {}),
  },

  /**
   * 本地方法 (轻量重要在前)
   */
  methods: {
    /**
     * 切换模式
     */
    changeMode(playMode) {
      const { one } = this
      if (!one.taskId) return

      CORE.merge(one, { controlCode: undefined, playMode })
      this.startSubmit()
    },

    /**
     * 调整控制
     */
    changeControl(control) {
      const { one, MAP } = this
      if (!one.taskId) return

      MAP.tipSubmit = MAP.TIP[control]
      CORE.merge(one, MAP.CONTROL[control])
      this.startSubmit()
    },

    /**
     * 调整音量
     */
    changeVolume(vol) {
      const { one } = this
      if (!one.taskId) return

      one.vol = vol
      this.startEdit()
    },
  },
}
</script>

<style lang="scss">
@import './index.scss';
</style>
